package exercise02;

public class MyRunnable implements Runnable{
    //第二种方式实现多线程，测试类中MyRunnable只创建一次，所以不需要加static
    int count = 100;
    @Override
    public void run() {
        while(true){
            synchronized (MyRunnable.class){
                if(count<10){
                    System.out.println("礼物还剩下" + count + "不再赠送");
                    break;
                }else{
                    count--;
                    System.out.println(Thread.currentThread().getName() + "在送礼物，礼物还剩下" + count + "个");
                }
            }
        }
    }
}
